var xmlhttp;
var maxtime = 4000;


function loadXMLDoc(){
	if (window.XMLHttpRequest){
	  xmlhttp=new XMLHttpRequest();
	}else{
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function update_history(domain,str,con,postUrl){
	isLv = ( postUrl == 'nlv' ? true : false);
		if(isLv)
			msg = 'Force leave the employee?';
		else
			msg = 'Change schedule of the employee?';
	var r = confirm(msg);
	
	if(r) updHistory(domain,str,con,postUrl);		
	else return false;
	
}

function updHistory(domain,str,con,postUrl){
	
		isLv = ( postUrl == 'nlv' ? true : false);
		bdy = ( isLv ? con+"hdr" : con+"body");  
		patt = "PATT"+con;
		cat = "CAT"+con;
		rem = "REM"+con;
		desc = "DESC"+con;
		href = con +"aref";
		tdref = con+"tdaref";
		force = con+"Force2lv";


		if  (isLv) {
			patt = document.getElementById('swscode').value;
			cat = document.getElementById('swscat').value;	
			rem = "";
			desc = document.getElementById('swsdesc').value;	
		}else{
			with (document.sFormViewDys){
				patt = eval(patt).value;
				cat = eval(cat).value;
				rem = eval(rem).value;
				desc = eval(desc).value;		 
			}	
		}
		tempHTML = document.getElementById(bdy).innerHTML;  
		document.getElementById(bdy).innerHTML = '<p style="text-align: center">Saving...</p>';
		
		if ( (isLv) || (patt != '' && cat != '') ){	
			str = str +"&rem="+rem+"&patt="+patt+"&cat="+cat;
			loadXMLDoc();
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState ==4 && xmlhttp.status ==200){
					ColdFusion.navigate('../manning/_getHist.cfm?'+str,'simHist');
					hidePop();
					if(isLv) {
						desc = document.getElementById(tdref).innerHTML + '<li><b>Vacation Leave</b></li>';
						document.getElementById(tdref).innerHTML = 
						'<span style="color:#F60;">'+desc+'</span>';	
						document.getElementById(tdref).style.textAlign = "center";		
						document.getElementById(tdref).style.cursor = "pointer";
						document.getElementById(tdref).title = "NOT YET POSTED";

						document.getElementById(bdy).innerHTML = tempHTML;
						if( document.getElementById(force).style.display == "block"){
							document.getElementById(force).style.display = "none";
						}

					}else{
						document.getElementById(href).innerHTML = 
						'<span style="color:#000;">'+desc+'</span>';
						document.getElementById(bdy).innerHTML = tempHTML;
						if( document.getElementById(force).style.display == "none"){
							document.getElementById(force).style.display = "block";
						}
					}
					
					alert('Schedule was successfuly updated.');
				}else if(xmlhttp.readyState ==4 && xmlhttp.status != 200){
					hidePop();
					alert('Error saving, connection to server was not established.\nPlease try again later!');
					document.getElementById(bdy).innerHTML = tempHTML;	
				}
			}
			url = domain+'eworksched/cfc/utility.cfm?'+postUrl+'=';
			xmlhttp.open('POST',url,true);
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");		
			xmlhttp.send(str);
		}else{
			alert('Please select new schedule code.');
		}			
}

function postWorksked(){
	vw = document.getElementById('docno').value;
	/*loadXMLDoc();
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState ==4 && xmlhttp.status ==200){
			ColdFusion.navigate('../manning/_getHist.cfm?'+str,'simHist');
			hidePop();
			if(isLv) {
				desc = 'Vacation Leave';
				document.getElementById(href).innerHTML = 
				'<span style="color:#00C;"><b>'+desc+'</b></span>';					
			}
			alert('Schedule was updated to '+desc+'.');
			document.getElementById(bdy).innerHTML = tempHTML;
		}else if(xmlhttp.readyState ==4 && xmlhttp.status != 200){
			hidePop();
			alert('Error saving, connection to server was not established.\nPlease try again later!');
			document.getElementById(bdy).innerHTML = tempHTML;	
		}
	}
	url = domain+'eworksched/cfc/utility.cfm?'+postUrl+'=';
	xmlhttp.open('POST',url,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");		
	xmlhttp.send(str);
*/
	ColdFusion.navigate('../manning/_postChanges.cfm?vw='+vw);
	
	
}




